<template>
  <div class="header-bar">
    <div class="header-top">
      <div class="header-left">
        <span class="weather">
          <span class="weather-icon"></span>
          {{ weather }}
        </span>
        <span class="time">{{ currentTime }}</span>
      </div>
      <div class="header-title-box">
        <div class="title-decoration">
          <dv-decoration-5 style="width:550px;height:30px;" :color="['#35a7e0', '#35a7e0']" :reverse="true" dur="3" />
        </div>
        <div class="header-title">{{ title }}</div>
      </div>
      <div class="header-right">
        <span class="header-icon avatar"></span>
        <span class="header-icon power"></span>
      </div>
    </div>
    <div class="header-bottom">
      <div class="btn-group left">
        <button class="header-btn" v-for="btn in leftBtns" :key="btn">{{ btn }}</button>
      </div>
      <div class="btn-group right">
        <button class="header-btn" v-for="btn in rightBtns" :key="btn">{{ btn }}</button>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue'
import { Decoration5 } from '@kjgl77/datav-vue3'

const props = defineProps({
  title: { type: String, default: '黑龙江省现代化水库运行管理矩阵省级平台' },
  weather: { type: String, default: '20-28℃ 晴转多云' },
  leftBtns: { type: Array, default: () => ['四全', '四制(治)'] },
  rightBtns: { type: Array, default: () => ['四预', '四管'] }
})

const currentTime = ref('2024-05-27 14:38:12') // 初始值设为图片中的时间
let timer: any = null

function updateTime() {
  const now = new Date()
  const y = now.getFullYear()
  const m = String(now.getMonth() + 1).padStart(2, '0')
  const d = String(now.getDate()).padStart(2, '0')
  const h = String(now.getHours()).padStart(2, '0')
  const min = String(now.getMinutes()).padStart(2, '0')
  const s = String(now.getSeconds()).padStart(2, '0')
  currentTime.value = `${y}-${m}-${d} ${h}:${min}:${s}`
}

onMounted(() => {
  updateTime()
  timer = setInterval(updateTime, 1000)
})

onUnmounted(() => {
  clearInterval(timer)
})

defineOptions({
  name: 'HeaderBar'
})
</script>

<style scoped>
.header-bar {
  width: 100%;
  height: auto;
  color: #fff;
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 100;
  font-family: 'Microsoft YaHei', Arial, sans-serif;
  padding: 0px 8px;
  background: linear-gradient(90deg, rgba(19, 66, 112, 0.6) 0%, rgba(255, 255, 255, 0) 50%, rgba(5, 32, 59, 0.48) 100%);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 340px;
}

.weather {
  font-size: 15px;
  opacity: 0.95;
  display: flex;
  align-items: center;
  gap: 4px;
}

.weather-icon {
  display: inline-block;
  width: 18px;
  height: 18px;
  background: url('data:image/svg+xml;utf8,<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="gold" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="5" fill="yellow"/><g stroke="gold"><line x1="12" y1="1" x2="12" y2="4"/><line x1="12" y1="20" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="6.34" y2="6.34"/><line x1="17.66" y1="17.66" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="4" y2="12"/><line x1="20" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="6.34" y2="17.66"/><line x1="17.66" y1="6.34" x2="19.78" y2="4.22"/></g></svg>') no-repeat center/contain;
}

.time {
  font-size: 15px;
  opacity: 0.95;
}

.header-title-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  min-width: 600px;
  padding: 0 20px;
}

.header-title {
  font-size: 22px;
  font-weight: bold;
  letter-spacing: 4px;
  color: #fff;
  text-shadow: 0 0 10px rgba(0, 207, 255, 0.8), 0 2px 4px rgba(0, 0, 10, 0.3);
  margin: 10px 0;
  position: relative;
  z-index: 1;
}

.title-decoration {
  position: absolute;
  top: 96%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 550px;
  height: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 220px;
  justify-content: flex-end;
}

.header-icon.avatar {
  display: inline-block;
  width: 28px;
  height: 28px;
  background: url('data:image/svg+xml;utf8,<svg fill="white" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="8" r="4" stroke="cyan" stroke-width="2" fill="none"/><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2" stroke="cyan" stroke-width="2" fill="none"/></svg>') no-repeat center/contain;
  opacity: 0.8;
  filter: drop-shadow(0 0 4px rgba(0, 207, 255, 0.6));
}

.header-icon.power {
  display: inline-block;
  width: 28px;
  height: 28px;
  background: url('data:image/svg+xml;utf8,<svg fill="white" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2v10m5.07-5.07a7 7 0 1 1-10.14 0" stroke="cyan" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="none"/></svg>') no-repeat center/contain;
  margin-left: 16px;
  opacity: 0.8;
  filter: drop-shadow(0 0 4px rgba(0, 207, 255, 0.6));
}

.header-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  opacity: 0.5;
}

.btn-group.left {
  display: flex;
  gap: 10px;
  margin-left: 120px;
}

.btn-group.right {
  display: flex;
  gap: 10px;
  margin-right: 120px;
}

.header-btn {
  background: linear-gradient(90deg, rgba(0, 180, 255, 0.8) 0%, rgba(0, 150, 255, 0.8) 100%);
  border: 1.5px solid rgba(60, 246, 255, 0.8);
  color: #fff;
  font-size: 16px;
  font-weight: bold;
  border-radius: 8px;
  padding: 6px 22px;
  box-shadow: 0 0 8px rgba(0, 207, 255, 0.3), inset 0 2px 8px rgba(0, 255, 255, 0.2);
  cursor: pointer;
  transition: all 0.2s ease;
  text-shadow: 0 0 6px rgba(0, 207, 255, 0.6);
  outline: none;
  position: relative;
  overflow: hidden;
}

.header-btn:hover {
  background: linear-gradient(90deg, rgba(0, 150, 255, 0.9) 0%, rgba(0, 180, 255, 0.9) 100%);
  box-shadow: 0 0 16px rgba(0, 207, 255, 0.6), inset 0 2px 12px rgba(0, 255, 255, 0.3);
  transform: translateY(-1px);
}

.header-btn::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(to bottom right,
      rgba(255, 255, 255, 0) 0%,
      rgba(255, 255, 255, 0.1) 50%,
      rgba(255, 255, 255, 0) 100%);
  transform: rotate(30deg);
  transition: all 0.3s ease;
}

.header-btn:hover::after {
  left: 100%;
}
</style>